Skip to content

Comments

Tg sequences#29

Open
oortsang wants to merge 4 commits intomainfrom
tg-sequences
Open

Tg sequences#29
oortsang wants to merge 4 commits intomainfrom
tg-sequences

Conversation

@oortsang
Copy link
Contributor

Ended up being a little more involved than I expected.. __getitem__ is left relatively intact for both TinyGraph and EdgeProxy, but __setitem__ needed to be modified for better error-handling (e.g. missing edges, poorly formatted requests). There's a weird edge case if you pass the same edge multiple times, but in opposite directions:

g = tg.TinyGraph(2)
g[[0, 1, 1], [1, 0, 0]] = [1, 2, 3]
# conflict??

I resolved this by reordering the vertex indices so that the first sequence always has the lower index, and this becomes equivalent to:

g[[0, 0, 0], [1, 1, 1]] = [1, 2, 3]
assert g.adjacency[0, 1] == g.adjacency[1, 0]
assert g.adjacency[0, 1] == 1 # I believe numpy breaks ties with the first value passed

which might still be weird, but at least numpy handles it for us and we still have a symmetric adjacency matrix. An alternate solution would be to set the elements of the adjacency matrix elementwise, but that requires extra casework (sequence/list vs int).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant